package com.xm.xmapp.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;

import com.xm.xmapp.R;
import com.xm.xmapp.app.CodeConstant;
import com.xm.xmapp.app.MyAppcation;
import com.xm.xmapp.base.MyBaseAdapter;
import com.xm.xmapp.base.ViewHolder;
import com.xm.xmapp.customview.CustomTextView;
import com.xm.xmapp.customview.CustomTextView.InnerStatus;
import com.xm.xmapp.response.bean.ResponseSystemMessageListBean;
import com.xm.xmapp.tools.StringTools;

public class SystemMessageAdapter extends MyBaseAdapter<ResponseSystemMessageListBean> {

	public SystemMessageAdapter(ArrayList<ResponseSystemMessageListBean> list, Activity context, int layoutId) {
		super(list, context, layoutId);

	}

	@Override
	public void setValues(ViewHolder holder, final ResponseSystemMessageListBean t, int position) {
		String title = "";
		if (t.city_name != null && !t.city_name.equals("")) {
			title = "【" + t.city_name + "】";
		}
		title = title + t.system_message_title;
		holder.setText(R.id.title, title).setText(R.id.content, StringTools.HtmlText(t.system_message_content))
				.setText(R.id.time, t.modified_on);
		final CustomTextView text = (CustomTextView) holder.getView(R.id.title);
		if (MyAppcation.getMyAppcation().queryData(CodeConstant.System_message, CodeConstant.System_message_id,
				t.system_message_id + MyAppcation.getMyAppcation().getUid())) {
			text.setVisibility(InnerStatus.GONE);
		} else {
			text.setVisibility(InnerStatus.VISIBLE);
		}

		holder.getConvertView().setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				MyAppcation.getMyAppcation().insertData(CodeConstant.System_message, CodeConstant.System_message_id,
						t.system_message_id + MyAppcation.getMyAppcation().getUid());
				text.setVisibility(InnerStatus.GONE);

				if (in != null) {
					in.DoSomeThing(t);
				}

			}
		});

	}

}
